﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace GaSaiGon.GUI
{
    public partial class frmCapNhatGaTau : Form
    {
        public frmCapNhatGaTau()
        {
            InitializeComponent();
            this.btnCapNhat.Click += new EventHandler(btnCapNhat_Click);
        }

        private void frmCapNhatGaTau_Load(object sender, EventArgs e)
        {
            string matau = Tag.ToString();
            GaTauBUS gtbus = new GaTauBUS();
            GaTauDTO gtdto = new GaTauDTO();
            gtdto.LayThongTinGaTau(matau);
            lb1.Text = gtbus.LayThongTinGaTau(gtdto).Rows[0]["MaTau"].ToString();
            txtsotoa.Text = gtbus.LayThongTinGaTau(gtdto).Rows[0]["SoToa"].ToString();
            txtghecung.Text = gtbus.LayThongTinGaTau(gtdto).Rows[0]["Soluong"].ToString();
            txtghedieuhoa.Text = gtbus.LayThongTinGaTau(gtdto).Rows[1]["Soluong"].ToString();
            txtgiuongnam.Text = gtbus.LayThongTinGaTau(gtdto).Rows[2]["Soluong"].ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        public delegate void SEND(string s);
        public SEND sender;
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
                string matau = Tag.ToString();
                if (txtsotoa.Text == "" || txtghecung.Text == "" || txtgiuongnam.Text == "" || txtghedieuhoa.Text == "")
                {
                    MessageBox.Show("Không được để trống những trường này!");
                    return;
                }
                else
                {
                    int sotoa = int.Parse(txtsotoa.Text);
                    int slghecung = int.Parse(txtghecung.Text);
                    int slghedieuhoa = int.Parse(txtghedieuhoa.Text);
                    int slgiuongnam = int.Parse(txtgiuongnam.Text);

                    GaTauBUS gtbus = new GaTauBUS();
                    GaTauDTO gtdto = new GaTauDTO();
                    gtdto.LayThongTinGaTau(matau);

                    string loaighe = gtbus.LayThongTinGaTau(gtdto).Rows[0]["LoaiGhe"].ToString();
                    int loai = int.Parse(loaighe);
                    string loaighe1 = gtbus.LayThongTinGaTau(gtdto).Rows[1]["LoaiGhe"].ToString();
                    int loai1 = int.Parse(loaighe1);
                    string loaighe2 = gtbus.LayThongTinGaTau(gtdto).Rows[2]["LoaiGhe"].ToString();
                    int loai2 = int.Parse(loaighe2);
                    gtdto.CapNhatGaTau(matau, sotoa, loai, slghecung);
                    gtbus.CapNhatGaTau(gtdto);

                    gtdto.CapNhatGaTau1(matau, sotoa, loai1, slghedieuhoa);
                    gtbus.CapNhatGaTau1(gtdto);

                    gtdto.CapNhatGaTau2(matau, sotoa, loai2, slgiuongnam);
                    gtbus.CapNhatGaTau2(gtdto);
                    MessageBox.Show("Cập nhật thông tin thành công!");
                    this.sender("Close");
                    Close();
                }
        }

    }
}
